package com.xinqing.test.LetCode;

/**
 * @Author:CHQ
 * @Date:2021/7/21 14:40
 * @Description
 */
public class Search {
    public static void main(String args[]){

        int[] nums={1,2,3,4,5};
        System.out.println(test(nums,2));
    }
    public static int test(int[] nums,int target){
        int left=0;
        int right=nums.length-1;
        while(left<=right){
            int mid=(left+right)/2;
            if(target==nums[mid]){
                return mid;
            }if(target<nums[mid]){
                right=mid-1;
            }else{
                left=mid+1;
            }
        }
        return -1;
    }
}
